﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GraphDrawing
{
    class izomorphizm
    {
        public List<List<Edge>> FindIzomorphizm (List<List<Edge>> treeList)
        {
            List<List<Edge>> izomorphizm = new List<List<Edge>>();
            for (int i = 0; i < treeList.Count; i++)
            {
                List<int> firstList = new List<int>();
                firstList = GetLevels(treeList[i]);
                for (int j = 0; j < treeList.Count; j++)
                {
                    List<int> secondList = new List<int>();
                    secondList = GetLevels(treeList[j]);
                    if (AreEqualList(firstList,secondList) && i!=j)
                    {
                        izomorphizm.Add(treeList[i]);
                        izomorphizm.Add(treeList[j]);
                        break;
                    }
                }
                if (izomorphizm.Count!=0)
                {
                    break;
                }
            }
            return izomorphizm;
        }

        public List<int> GetLevels (List<Edge> tree)
        {
            List<int> vertexLevels = new List<int>();
            
                for (int i = 0; i < tree.Count+1; i++)
                {
                    vertexLevels.Add(0);
                    for (int j = 0; j < tree.Count; j++)
                    {
                        if (tree[j].v1 == i)
                        {
                            vertexLevels[i]++;
                        }
                        if (tree[j].v2 == i)
                        {
                            vertexLevels[i]++;
                        }
                    }
                }
            vertexLevels.Sort();
            return vertexLevels;

        }

        public bool AreEqualList (List<int> a, List<int> b)
        {
            int check = 0;
            for (int i = 0; i < a.Count; i++)
            {
                if (a[i]==b[i])
                {
                    check++;
                }
                
            }
            if (check == a.Count)
            {
                return true;
            }
            else
                return false;

        }
    }
}
